package com.yohann.designPattern.factory.simpleFactory.comsume;

import com.yohann.designPattern.factory.simpleFactory.factory.SimpleFactory;
import com.yohann.designPattern.factory.simpleFactory.pizza.Pizza;

import java.util.Scanner;

/**
 * <p>
 * 订购披萨🍕
 * </p>
 *
 * @author Yohann
 * @since 2021/2/1 13:22
 */
public class OrderPizza {
    private final Scanner scanner = new Scanner(System.in);
    private SimpleFactory simpleFactory;
    private Pizza pizza;

    public OrderPizza(SimpleFactory simpleFactory) {
        this.setSimpleFactory(simpleFactory);
    }

    private void setSimpleFactory(SimpleFactory simpleFactory) {
        this.simpleFactory = simpleFactory;

        do {
            String type = scanner.nextLine();
            this.pizza = this.simpleFactory.createPizza(type);

            if (pizza != null) {
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            }
        } while (true);
    }
}